<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            background-color: #000;
        }

        .box {
            position: relative;
            width: 1000px;
            height: 42px;
            background: #fff url('./image/rss.png') no-repeat right center;
            margin: 50px auto;
        }

        .box ul {
            position: absolute;
            top: 0;
            left: 0;
            list-style: none;
            z-index: 3;
        }

        .box ul li {
            height: 42px;
            width: 83px;
            float: left;
            line-height: 42px;
            text-align: center;
            cursor: pointer;
        }

        .box span {
            position: absolute;
            top: 0;
            left: 0;
            width: 83px;
            height: 42px;
            background: url(./image/cloud.gif) no-repeat center;
        }
    </style>

</head>

<body>
    <div class="box">
        <ul>
            <li>新闻首页</li>
            <li>新闻首页</li>
            <li>新闻首页</li>
            <li>新闻首页</li>
            <li>新闻首页</li>
            <li>新闻首页</li>
            <li>新闻首页</li>
            <li>新闻首页</li>
        </ul>
        <span id="cloud"></span>
    </div>
</body>

</html>
<script>
    //获取所有li
    var lis = document.querySelectorAll("li")
    var cloud = document.querySelector('#cloud')
    //声明缓速运动属性
    var target = 0
    var leader = 0
    //当前点击位置
    var current = 0
    //循环lis
    lis.forEach((item, index) => {
        //lis鼠标移入事件
        item.onmouseover = function () {
            target = this.offsetLeft
        }
        item.onclick = function () {
            current = target
        }
        item.onmouseout = function () {
            target = current
        }
    })
    function fn() {
        leader = leader + (target - leader) / 10
        cloud.style.left = leader + 'px'
    }
    setInterval(fn, 30)
</script>